<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>代码块高亮：启用高亮/代码块块样式/行号 - Vditor</title>
    <meta name="robots" content="index,follow,archive">
    <meta name="description"
          content="Vditor 支持大纲、数学公式、脑图、图表、流程图、甘特图、时序图、五线谱、多媒体、语音阅读、标题锚点、代码高亮及复制、graphviz 渲染"/>
    <meta name="copyright" content="B3log"/>
    <link rel="canonical" href="https://vditor.b3log.org/demo/advanced-hljs.html">
    <link rel="apple-touch-icon" href="//static.b3log.org/images/brand/vditor-128.png">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Window-target" content="_top"/>
    <link rel="icon" type="image/png" href="//static.b3log.org/images/brand/vditor-128.png"/>
    <link rel="shortcut icon" type="image/x-icon" href="//static.b3log.org/images/brand/vditor-512.png"/>
    <link type="text/css" rel="stylesheet" href="//static.b3log.org/css/base.css" charset="utf-8"/>

    <meta property="og:locale" content="zh_CN"/>
    <meta property="og:title" content="代码块高亮：启用高亮/代码块块样式/行号 - Vditor"/>
    <meta property="og:description"
          content="Vditor 支持大纲、数学公式、脑图、图表、流程图、甘特图、时序图、五线谱、多媒体、语音阅读、标题锚点、代码高亮及复制、graphviz 渲染"/>
    <meta property="og:image" content="https://static.b3log.org/images/brand/vditor-128.png"/>
    <meta property="og:url" content="https://vditor.b3log.org"/>
    <meta property="og:site_name" content="B3log"/>
    <meta name="twitter:card" content="summary_large_image"/>
    <meta name="twitter:description"
          content="Vditor 支持大纲、数学公式、脑图、图表、流程图、甘特图、时序图、五线谱、多媒体、语音阅读、标题锚点、代码高亮及复制、graphviz 渲染"/>
    <meta name="twitter:title" content="代码块高亮：启用高亮/代码块块样式/行号 - Vditor"/>
    <meta name="twitter:image" content="https://static.b3log.org/images/brand/vditor-128.png"/>
    <meta name="twitter:url" content="https://vditor.b3log.org"/>
    <meta name="twitter:site" content="@b3logos"/>
    <meta name="twitter:creator" content="@b3logos"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vditor@latest/dist/index.css"/>
    <script src="//vditor.b3log.org/vditor.js?v1.0.0" defer></script>
    <style>
        .header {
            background-color: #fff;
            box-shadow: rgba(0, 0, 0, 0.05) 0 1px 7px;
            border-bottom: 1px solid #e1e4e8;
        }

        .label {
            margin: 0 10px 10px 0;
        }

        .btn--small {
            margin-right: 20px;
        }
    </style>
</head>
<body>
<div class="header fn-clear">
    <a class="header-logo" href="https://vditor.b3log.org">
        <img src="//static.b3log.org/images/brand/vditor-128.png">
        <h1>Vditor</h1>
    </a>
    <div class="fn-clear">
        <a class="header-a" href="https://hacpai.com/tag/vditor" target="_blank">社区</a>
        <a class="header-a header-red" target="_blank" href="https://hacpai.com/article/1549638745630">API</a>
        <a class="header-a header-green current" href="index.html">Demo</a>
        <a class="header-a header-yellow" href="https://hacpai.com/sponsor" target="_blank">成为赞助者</a>
    </div>
</div>
<div class="wrapper">
    <div class="fn-50"></div>
    相关 <a href="https://hacpai.com/article/1549638745630#options-preview-hljs" target="_blank">API</a>：
    options.preview.hljs.enable，options.preview.hljs.style，options.preview.hljs.lineNumber
    <div class="fn-50"></div>
    <div style="display: flex;align-items: center">
        <button class="btn--small btn" onclick="setHljs(this, {preview: {hljs:{enable:false}}})">禁用代码高亮</button>
        <button class="btn--small btn" onclick="setHljs(this, {preview: {hljs:{lineNumber:true}}})">启用行号</button>
        <span class="label">代码块主题</span>
        <select class="btn btn--small" id="codeTheme">
            <option>abap</option>
            <option>algol</option>
            <option>algol_nu</option>
            <option>arduino</option>
            <option>autumn</option>
            <option>borland</option>
            <option>bw</option>
            <option>colorful</option>
            <option>dracula</option>
            <option>emacs</option>
            <option>friendly</option>
            <option>fruity</option>
            <option selected>github</option>
            <option>igor</option>
            <option>lovelace</option>
            <option>manni</option>
            <option>monokai</option>
            <option>monokailight</option>
            <option>murphy</option>
            <option>native</option>
            <option>paraiso-dark</option>
            <option>paraiso-light</option>
            <option>pastie</option>
            <option>perldoc</option>
            <option>pygments</option>
            <option>rainbow_dash</option>
            <option>rrt</option>
            <option>solarized-dark</option>
            <option>solarized-dark256</option>
            <option>solarized-light</option>
            <option>swapoff</option>
            <option>tango</option>
            <option>trac</option>
            <option>vim</option>
            <option>vs</option>
            <option>xcode</option>
        </select>
    </div>
    <div id="vditor"></div>
    <div id="vditorDemoCode" class="vditor-reset">
        <pre><code class="javascript">new Vditor('vditor', {
  height: 360,
  cache: {
    enable: false,
  },
  preview: {
    hljs: {
      enable: false,
    },
  },
  value: `\`\`\`go
package main

import "fmt"

func main() {
\tfmt.Println("Hello, 世界")
}
\`\`\``,
    })</code></pre>
    </div>
    <div class="fn-100"></div>
    <div class="fn-clear">
        <h2 class="fn-left">参与讨论</h2>
        <span class="fn-right" style="line-height: 36px" id="commentCnt"></span>
    </div>
    <div class="fn-50"></div>
    <div id="vditorComments"></div>
    <div class="fn-100"></div>
</div>
<!-- end main -->

<div class="footer">
    <div class="wrapper fn-clear">
        <a href="https://b3log.org">首页</a> &nbsp; &nbsp;
        <a href="https://hacpai.com" target="_blank">社区</a> &nbsp; &nbsp;
        <a href="https://b3log.org/brand-marking.html">品牌标识</a> &nbsp; &nbsp;
        <a href="https://hacpai.com/sponsor" target="_blank">成为赞助者</a>
        <div class="fn-right">
            © 2010-present <a href="https://b3log.org">B3log 开源</a>旗下云南链滴科技有限公司
        </div>
    </div>
</div>
<script>
  const setHljs = (it, options) => {
    document.getElementById('vditor').innerHTML = ''
    const mergedOptions = Object.assign({
      height: 360,
      cache: {
        enable: false,
      },
      value: `\`\`\`go
package main

import "fmt"

func main() {
\tfmt.Println("Hello, 世界")
}
\`\`\``,
    }, options)

    if (it) {
      updateCode(it, `new Vditor('vditor', ${JSON.stringify(mergedOptions, null, '  ')})`)
    }
    new Vditor('vditor', mergedOptions)
  }
  vditorScript = setHljs
  document.querySelector('#codeTheme').onchange = function () {
    setHljs(this, {
      preview: {
        hljs: {
          style: document.getElementById('codeTheme').value,
        },
      },
    })
  }
</script>
</body>
</html>
